package com.freedom.admin.application.service.cmd;

import com.freedom.admin.application.converter.DeptConverter;
import com.freedom.admin.domain.service.DeptService;
import com.freedom.admin.infrastructure.persistence.pojo.bo.DeptBO;
import com.freedom.admin.infrastructure.persistence.pojo.form.DeptForm;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor
public class DeptCmdService {

    private final DeptService deptService;

    private final DeptConverter deptConverter;

    @Transactional(rollbackFor = Exception.class)
    public Boolean modifyDept(DeptForm deptForm) {
        DeptBO deptBO = deptConverter.toBO(deptForm);
        deptService.modifyDept(deptBO);
        return Boolean.TRUE;
    }

    @Transactional(rollbackFor = Exception.class)
    public Boolean addDept(DeptForm deptForm) {
        DeptBO deptBO = deptConverter.toBO(deptForm);
        deptService.addDept(deptBO);
        return Boolean.TRUE;
    }

    @Transactional(rollbackFor = Exception.class)
    public Boolean removeDept(List<Integer> ids) {
        deptService.removeDept(ids);
        return Boolean.TRUE;
    }
}
